package com.edu.exam.entity.examination.paper.technical;

import com.edu.exam.enums.examination.paper.OmQualityGrade;
import com.edu.exam.enums.examination.paper.OmEvaluationMethod;
import com.edu.exam.enums.examination.paper.OmQualityStatus;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * OMR识别质量评估实体类
 * 所属模块：E-01 考试执行模块
 * 对应数据库表：om_quality_assessment
 *
 * <p>根据E-04-03 OMR识别子模块数据库设计实现，
 * 存储OMR识别质量评估的详细信息，包括整体评分、分项评分、质量问题统计等。
 * 用于评估OMR识别结果的质量和可靠性。</p>
 *
 * @author System
 * @version 1.0.0
 */

@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class OmQualityAssessment {

    /**
     * 质量评估ID，主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 关联信息
     */
    @Column(name = "result_id", nullable = false)
    private Long resultId;

    @Column(name = "evaluation_rule_id")
    private Long evaluationRuleId;

    /**
     * 整体质量评估
     */
    @Column(name = "overall_score", precision = 5, scale = 2, nullable = false)
    private Double overallScore;

    @Enumerated(EnumType.STRING)
    @Column(name = "quality_grade", length = 5, nullable = false)
    private OmQualityGrade qualityGrade;

    @Column(name = "confidence_level", precision = 5, scale = 2)
    private Double confidenceLevel;

    /**
     * 分项质量评分
     */
    @Column(name = "exam_number_score", precision = 5, scale = 2)
    private Double examNumberScore;

    @Column(name = "answer_recognition_score", precision = 5, scale = 2)
    private Double answerRecognitionScore;

    @Column(name = "format_consistency_score", precision = 5, scale = 2)
    private Double formatConsistencyScore;

    @Column(name = "image_quality_score", precision = 5, scale = 2)
    private Double imageQualityScore;

    /**
     * 质量问题统计
     */
    @Column(name = "total_issues")
    private Integer totalIssues;

    @Column(name = "critical_issues")
    private Integer criticalIssues;

    @Column(name = "major_issues")
    private Integer majorIssues;

    @Column(name = "minor_issues")
    private Integer minorIssues;

    /**
     * 具体质量问题（JSON格式）
     */
    @Column(name = "issue_details", columnDefinition = "TEXT")
    private String issueDetails;

    @Column(name = "affected_questions", columnDefinition = "TEXT")
    private String affectedQuestions;

    @Column(name = "recommended_actions", columnDefinition = "TEXT")
    private String recommendedActions;

    /**
     * 评估信息
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "evaluation_method", length = 20, nullable = false)
    private OmEvaluationMethod evaluationMethod;

    @Column(name = "evaluation_algorithm", length = 100)
    private String evaluationAlgorithm;

    @Column(name = "evaluation_time", nullable = false)
    private LocalDateTime evaluationTime;

    @Column(name = "evaluation_duration_ms")
    private Integer evaluationDurationMs;

    /**
     * 人工评估信息
     */
    @Column(name = "manual_evaluator_id")
    private Long manualEvaluatorId;

    @Column(name = "manual_evaluation_time")
    private LocalDateTime manualEvaluationTime;

    @Column(name = "manual_evaluation_notes", columnDefinition = "TEXT")
    private String manualEvaluationNotes;

    @Column(name = "is_override_automatic")
    private Boolean isOverrideAutomatic;

    /**
     * 状态信息
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "quality_status", length = 20, nullable = false)
    private OmQualityStatus qualityStatus;

    @Column(name = "review_required")
    private Boolean reviewRequired;

    // 审计字段

    /**
     * 创建时间
     */
    @CreationTimestamp
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @UpdateTimestamp
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 创建人ID
     */
    @Column(name = "creator_id", length = 64)
    private String creatorId;

    /**
     * 更新人ID
     */
    @Column(name = "updater_id", length = 64)
    private String updaterId;

    /**
     * 版本号（乐观锁）
     */
    @Version
    @Column(name = "version")
    private Integer version = 0;

    /**
     * 逻辑删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;
}